package org.wu.framework.lazy.orm.database.jpa.repository.support;


import org.wu.framework.core.exception.RuntimeExceptionFactory;
import org.wu.framework.lazy.orm.database.jpa.repository.enums.QueryType;
import org.wu.framework.lazy.orm.database.jpa.repository.query.LazyQueryMetadata;
import org.wu.framework.lazy.orm.database.jpa.repository.support.delete.LazySimpleDeleteQuerySupport;
import org.wu.framework.lazy.orm.database.jpa.repository.support.insert.LazySimpleInsertQuerySupport;
import org.wu.framework.lazy.orm.database.jpa.repository.support.select.LazySimpleSelectQuerySupport;
import org.wu.framework.lazy.orm.database.jpa.repository.support.update.LazySimpleUpdateQuerySupport;


/**
 * 注意需要缓存 方法避免重复创建
 */
public class LazySimpleQueryFactory {


    /**
     * 创建 LazySimpleQuerySupport
     *
     * @param lazyQueryMetadata 元数据
     * @return LazySimpleQuerySupport
     */
    public static LazySimpleQuerySupport createLazySimpleQuerySupport(LazyQueryMetadata lazyQueryMetadata) {

        // 缓存
        QueryType queryType = lazyQueryMetadata.getQueryType();
        switch (queryType) {
            case SELECT -> {
                LazySimpleSelectQuerySupport lazySimpleSelectQuerySupport = new LazySimpleSelectQuerySupport(lazyQueryMetadata);
                return lazySimpleSelectQuerySupport;
            }
            case INSERT -> {
                LazySimpleInsertQuerySupport lazySimpleInsertQuerySupport = new LazySimpleInsertQuerySupport(lazyQueryMetadata);
                return lazySimpleInsertQuerySupport;
            }
            case UPDATE -> {
                LazySimpleUpdateQuerySupport lazySimpleUpdateQuerySupport = new LazySimpleUpdateQuerySupport(lazyQueryMetadata);
                return lazySimpleUpdateQuerySupport;
            }
            case DELETE -> {
                LazySimpleDeleteQuerySupport lazySimpleDeleteQuerySupport = new LazySimpleDeleteQuerySupport(lazyQueryMetadata);
                return lazySimpleDeleteQuerySupport;
            }
            default -> {
                RuntimeExceptionFactory.of("Unsupported query type: " + queryType);
                return null;
            }
        }
    }



}
